# Node - The Process Object
A process is the instance of a computer program that is being executed. (-› Activity Monitor)
Node has a global process
object with useful methods and information about the current process.
https://nodejs.org/api/process.html
# process.env
is an object which stores and controls information about the environment in which the process is currently running.
contains a
PWD
property which holds a string with the directory in which the current process is located.-› convention is to add a property to
process.env
with the keyNODE_ENV
and a value of eitherproduction
ordevelopment
.if (process.env.NODE_ENV === 'development'){ console.log('Testing! Testing! Does everything work?'); }
# process.memoryUsage()
returns information on the CPU demands of the current process.
similar to this:
{ rss: 26247168,
heapTotal: 5767168,
heapUsed: 3573032,
external: 8772 }
Heap can mean different things in different contexts: a heap can refer to a specific data structure (opens new window), but it can also refer to the a block of computer memory (opens new window).
process.memoryUsage().heapUsed
will return a number representing how many bytes of memory the current process is using.
# process.argv
holds an array of command line values provided when the current process was initiated.
absolute path to Node, which ran the process
path to the file that’s running
following elements will be any command line arguments provided when the process was initiated
node myProgram.js testing several features
console.log(process.argv[3]); // Prints 'several'
process.argv[2]
-› first parameter